package com.example.demo.myThread;

public class Interrupt extends Thread {
    volatile boolean flag = false;

    @Override
    public void run() {
        while (!flag){
            System.out.println(this.getName()+" is running !!!!!");
            try {
                sleep(1000);
            } catch (InterruptedException e) {
                System.out.println("wake up from block");
                flag = true;
            }
        }
        System.out.println(getName()+" is exit !!!!!");
    }
}


class TestInterrupt{

    public static void main(String[] args) throws InterruptedException {
        Interrupt i = new Interrupt();
        System.out.println("Thread is start !!!!!!");
        i.start();
        Thread.sleep(3000);
        System.out.println("Interrupt is "+ i.getName());
        i.flag = true;
        i.interrupt();
        Thread.sleep(3000);
        System.out.println("stop application!!!!");
    }
}